package controller

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"project_base_framework/params"
	"project_base_framework/service"
)

type UserController struct {
}

func NewUserController() *UserController {
	return &UserController{}
}

func (userController *UserController) Login(context *gin.Context) {
	var userService = service.NewUserService()
	//var loginParamVO *params.LoginParamVO
	//loginParamVO = new(params.LoginParamVO)
	loginParamVO := &params.LoginParamVO{}
	if err := context.ShouldBindJSON(loginParamVO); err != nil {
		fmt.Println("param error :", err.Error())
		context.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  "参数错误",
		})
		return
	}
	loginResponseDTO, err := userService.Login(loginParamVO)
	if err != nil {
		fmt.Println("login error :", err.Error())
		context.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  "登录失败",
		})
		return
	}
	context.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"data": loginResponseDTO,
	})
}
